package com.ruoyi.mall.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.domain.OrderBanch;
import com.ruoyi.mall.service.IOrderBanchService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 盲盒批量订单Controller
 *
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/mall/banch")
public class OrderBanchController extends BaseController {
    @Autowired
    private IOrderBanchService orderBanchService;

    /**
     * 查询盲盒批量订单列表
     */
    @PreAuthorize("@ss.hasPermi('mall:banch:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderBanch orderBanch) {
        startPage();
        List<OrderBanch> list = orderBanchService.selectOrderBanchList(orderBanch);
        return getDataTable(list);
    }

    /**
     * 导出盲盒批量订单列表
     */
    @PreAuthorize("@ss.hasPermi('mall:banch:export')")
    @Log(title = "盲盒批量订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderBanch orderBanch) {
        List<OrderBanch> list = orderBanchService.selectOrderBanchList(orderBanch);
        ExcelUtil<OrderBanch> util = new ExcelUtil<OrderBanch>(OrderBanch.class);
        util.exportExcel(response, list, "盲盒批量订单数据");
    }

    /**
     * 获取盲盒批量订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:banch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(orderBanchService.selectOrderBanchById(id));
    }

    /**
     * 新增盲盒批量订单
     */
    @PreAuthorize("@ss.hasPermi('mall:banch:add')")
    @Log(title = "盲盒批量订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderBanch orderBanch) {
        return toAjax(orderBanchService.insertOrderBanch(orderBanch));
    }

    /**
     * 修改盲盒批量订单
     */
    @PreAuthorize("@ss.hasPermi('mall:banch:edit')")
    @Log(title = "盲盒批量订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderBanch orderBanch) {
        return toAjax(orderBanchService.updateOrderBanch(orderBanch));
    }

    /**
     * 删除盲盒批量订单
     */
    @PreAuthorize("@ss.hasPermi('mall:banch:remove')")
    @Log(title = "盲盒批量订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(orderBanchService.deleteOrderBanchByIds(ids));
    }
}
